
void readFile(const string&& AbsoluteSourcePath, int head, void(*cb)(const  string&))
{
	ifstream file(AbsoluteSourcePath);
	string str;
	if (head)
	{
		getline(file, str);
	}
	while (getline(file, str))
	{
		cb(str);
	}
}


class FileAdapter{
public:
    typedef void  (* TXT_CB)(const  string&);  //每次读到消息， cb都会被call一次
    typedef void  (* BIN_CB)(const  string&);

    struct  FileCloseDeleter{
        void operator()(ofstream * ofs) {
            ofs->close();
        }
    };

    static  FileAdapter & GetInstance(){
            static FileAdapter instance;
            return  instance;
    }
    void flush_to_file(const string & file,string& msg) {
        if (fp_.find(file) != fp_.end()) {
            const auto & ofs = fp_.find(file)->second;
            *ofs <<msg;
        } else {
            unique_ptr<std::ofstream,FileCloseDeleter> ofs(new std::ofstream);
            ofs->open(file, std::ofstream::out | std::ofstream::app);
            fp_.insert( make_pair(file,std::move(ofs)));
            *(fp_[file]) << msg;
        }
    }
    void read_txt(const string  & file, TXT_CB cb){
        ifstream fp("file");
        string str;
        while(getline(fp,str)){
            cb(str);
        }
    }
    int binary_sse_tick(const string & flile, BIN_CB cb ) {

        string file("file");
        // FILE* fp = fopen(file.c_str(), "wb+");
        FILE *fp =  fopen(file.c_str(),"r");
        const int  msg_head =  sizeof(msg_sse_head);
        // constexpr int  widx = msg_head + max(sizeof(sse_hpf_order), sizeof(sse_hpf_exe));
        char buff[128] = {};
        memset(buff, 0 , sizeof(buff));
        // int padding = 4;
        int read_size = sizeof(sse_hpf_exe) + sizeof(uint64_t) + sizeof(uint16_t);

        while (fread(buff, read_size + 4 ,1,fp)) {
            uint32_t w_time = 0  ;// = reinterpret_cast<uint64_t> (buff);
            sse_hpf_head* p = reinterpret_cast<sse_hpf_head*> (buff + sizeof(uint64_t) + sizeof(uint16_t));

            int type = p->m_msg_type;

            if (type == SSE_ORDER_MSG_TYPE) {
                sse_hpf_order* q = reinterpret_cast<sse_hpf_order*> (buff + sizeof(uint64_t) + sizeof(uint16_t));
                string msg ;
                //do somethig
                cb(msg);
            }
            else if (type == SSE_EXECUTION_MSG_TYPE){
                sse_hpf_exe* q = reinterpret_cast<sse_hpf_exe*> (buff + sizeof(uint64_t) + sizeof(uint16_t));
                string msg;
                //do something
                cb(msg);
            }
            memset(buff, 0 , sizeof(buff));
        }
        return 1;
    }
private:
    unordered_map<string, unique_ptr<ofstream ,FileCloseDeleter> > fp_;
    FileAdapter(){
    }
};
